<!DOCTYPE HTML>
<html lang="zh-hans" >
    <!-- Start book Python基础 -->
<!-- Start book Python基础 -->
    <head>
        <!-- head:start -->
<!-- head:start -->
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <title>列表推导式 | Python基础</title>
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <meta name="description" content="">
        <meta name="generator" content="GitBook 2.6.7">
        <meta name="author" content="姜伟">
        
        <meta name="HandheldFriendly" content="true"/>
        <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta name="apple-mobile-web-app-status-bar-style" content="black">
        <link rel="apple-touch-icon-precomposed" sizes="152x152" href="gitbook/images/apple-touch-icon-precomposed-152.png">
        <link rel="shortcut icon" href="gitbook/images/favicon.ico" type="image/x-icon">
        
    <link rel="stylesheet" href="gitbook/style.css">
    
        
        <link rel="stylesheet" href="gitbook/plugins/gitbook-plugin-prism/prism.css">
        
    
        
        <link rel="stylesheet" href="gitbook/plugins/gitbook-plugin-splitter/splitter.css">
        
    
        
        <link rel="stylesheet" href="gitbook/plugins/gitbook-plugin-toggle-chapters/toggle.css">
        
    
        
        <link rel="stylesheet" href="gitbook/plugins/gitbook-plugin-highlight/website.css">
        
    
        
        <link rel="stylesheet" href="gitbook/plugins/gitbook-plugin-fontsettings/website.css">
        
    
    

        
    
    
    <link rel="next" href="./chapter06.html" />
    
    
    <link rel="prev" href="./chapter04.html" />
    

        <!-- head:end -->
<!-- head:end -->
    </head>
    <body>
        <!-- body:start -->
<!-- body:start -->
        
    <div class="book"
        data-level="5"
        data-chapter-title="列表推导式"
        data-filepath="chapter05.md"
        data-basepath="."
        data-revision="Fri Feb 07 2020 10:06:55 GMT+0800 (CST)"
        data-innerlanguage="">
    

<div class="book-summary">
    <nav role="navigation">
        <ul class="summary">
            
            
            
            

            

            
    
        <li class="chapter " data-level="0" data-path="index.html">
            
                
                    <a href="./index.html">
                
                        <i class="fa fa-check"></i>
                        
                        学习目标
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1" data-path="chapter01.html">
            
                
                    <a href="./chapter01.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.</b>
                        
                        列表的基本使用
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2" data-path="chapter02.html">
            
                
                    <a href="./chapter02.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.</b>
                        
                        列表的增删改查
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3" data-path="chapter03.html">
            
                
                    <a href="./chapter03.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.</b>
                        
                        列表的遍历
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4" data-path="chapter04.html">
            
                
                    <a href="./chapter04.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.</b>
                        
                        列表的嵌套
                    </a>
            
            
        </li>
    
        <li class="chapter active" data-level="5" data-path="chapter05.html">
            
                
                    <a href="./chapter05.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.</b>
                        
                        列表推导式
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6" data-path="chapter06.html">
            
                
                    <a href="./chapter06.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.</b>
                        
                        列表的复制
                    </a>
            
            
        </li>
    


            
            <li class="divider"></li>
            <li>
                <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
                    本书使用 GitBook 发布
                </a>
            </li>
            
        </ul>
    </nav>
</div>

    <div class="book-body">
        <div class="body-inner">
            <div class="book-header" role="navigation">
    <!-- Actions Left -->
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="./" >Python基础</a>
    </h1>
</div>

            <div class="page-wrapper" tabindex="-1" role="main">
                <div class="page-inner">
                
                
                    <section class="normal" id="section-">
                    
                        <h2 id="&#x5217;&#x8868;&#x63A8;&#x5BFC;&#x5F0F;">&#x5217;&#x8868;&#x63A8;&#x5BFC;&#x5F0F;</h2>
<p>&#x6240;&#x8C13;&#x7684;&#x5217;&#x8868;&#x63A8;&#x5BFC;&#x5F0F;&#xFF0C;&#x5C31;&#x662F;&#x6307;&#x7684;&#x8F7B;&#x91CF;&#x7EA7;&#x5FAA;&#x73AF;&#x521B;&#x5EFA;&#x5217;&#x8868;</p>
<h3 id="1-&#x57FA;&#x672C;&#x7684;&#x65B9;&#x5F0F;">1. &#x57FA;&#x672C;&#x7684;&#x65B9;&#x5F0F;</h3>
<p><img src="imgs/&#x5217;&#x8868;&#x63A8;&#x5BFC;&#x5F0F;1.png" alt=""></p>
<h3 id="2-&#x5728;&#x5FAA;&#x73AF;&#x7684;&#x8FC7;&#x7A0B;&#x4E2D;&#x4F7F;&#x7528;if">2. &#x5728;&#x5FAA;&#x73AF;&#x7684;&#x8FC7;&#x7A0B;&#x4E2D;&#x4F7F;&#x7528;if</h3>
<p><img src="imgs/&#x5217;&#x8868;&#x63A8;&#x5BFC;&#x5F0F;2.png" alt=""></p>
<h3 id="3-2&#x4E2A;for&#x5FAA;&#x73AF;">3. 2&#x4E2A;for&#x5FAA;&#x73AF;</h3>
<p><img src="imgs/&#x5217;&#x8868;&#x63A8;&#x5BFC;&#x5F0F;3.png" alt=""></p>
<h3 id="4-3&#x4E2A;for&#x5FAA;&#x73AF;">4. 3&#x4E2A;for&#x5FAA;&#x73AF;</h3>
<p><img src="imgs/&#x5217;&#x8868;&#x63A8;&#x5BFC;&#x5F0F;4.png" alt=""></p>
<h3 id="&#x7EC3;&#x4E60;">&#x7EC3;&#x4E60;</h3>
<p>&#x8BF7;&#x5199;&#x51FA;&#x4E00;&#x6BB5; Python &#x4EE3;&#x7801;&#x5B9E;&#x73B0;&#x5206;&#x7EC4;&#x4E00;&#x4E2A; list &#x91CC;&#x9762;&#x7684;&#x5143;&#x7D20;,&#x6BD4;&#x5982; [1,2,3,...100]&#x53D8;&#x6210; [[1,2,3],[4,5,6]....]</p>
<p>&#x53C2;&#x8003;&#x7B54;&#x6848;&#xFF1A;</p>
<pre><code class="lang-python">a = [x <span class="hljs-keyword">for</span> x <span class="hljs-keyword">in</span> range(<span class="hljs-number">1</span>,<span class="hljs-number">101</span>)]
b = [a[x:x+<span class="hljs-number">3</span>] <span class="hljs-keyword">for</span> x <span class="hljs-keyword">in</span> range(<span class="hljs-number">0</span>,len(a),<span class="hljs-number">3</span>)]
</code></pre>

                    
                    </section>
                
                
                </div>
            </div>
        </div>

        
        <a href="./chapter04.html" class="navigation navigation-prev " aria-label="Previous page: 列表的嵌套"><i class="fa fa-angle-left"></i></a>
        
        
        <a href="./chapter06.html" class="navigation navigation-next " aria-label="Next page: 列表的复制"><i class="fa fa-angle-right"></i></a>
        
    </div>
</div>

        
<script src="gitbook/app.js"></script>

    
    <script src="gitbook/plugins/gitbook-plugin-splitter/splitter.js"></script>
    

    
    <script src="gitbook/plugins/gitbook-plugin-copy-code-button/toggle.js"></script>
    

    
    <script src="gitbook/plugins/gitbook-plugin-toggle-chapters/toggle.js"></script>
    

    
    <script src="gitbook/plugins/gitbook-plugin-fontsettings/buttons.js"></script>
    

<script>
require(["gitbook"], function(gitbook) {
    var config = {"prism":{},"splitter":{},"copy-code-button":{},"toggle-chapters":{},"highlight":{},"fontsettings":{"theme":"white","family":"sans","size":2}};
    gitbook.start(config);
});
</script>

        <!-- body:end -->
<!-- body:end -->
    </body>
    <!-- End of book Python基础 -->
<!-- End of book Python基础 -->
</html>
